package com.dhc.quartz;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;


public class JobScheduler implements org.quartz.Job {


    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {

        System.out.println("执行了");
    }

    public static void main(String[] args) throws Exception{
        //Scheduler调度器 工厂中获取调度实例
        Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
        //Job任务实例
        JobDetail jobDetail = JobBuilder.newJob(JobScheduler.class)
                .withIdentity("job1", "jobGroup1")//1任务名2组名
                .build();

        //Trigger触发器
        Trigger simpleTrigger = TriggerBuilder.newTrigger()
                .withIdentity("trigger1", "triggerGroup1")
                .startNow()//马上启动触发器
                .withSchedule(CronScheduleBuilder.cronSchedule("* * * * * ?"))
                .build();
        //让调度器关联任务和触发器
        scheduler.scheduleJob(jobDetail,simpleTrigger);
        //启动
        scheduler.start();
        //挂起
//        scheduler.standby();
        //关闭 true(当前任务执行完成后关闭) false(立即关闭)
        scheduler.shutdown(true);
        scheduler.shutdown(false);

        //重新启动
//        scheduler.start();
    }
}
